/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.catalogos.prueba.business;

import com.catalogos.prueba.entities.AtributoCatalogo;
import com.catalogos.prueba.entities.CamposCatalogo;
import com.catalogos.prueba.entities.ValorCatalogo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 874836
 */
public class CampoValorService {



      public Map<String, List<CamposCatalogo>> getCampoValor(int idCat){
          Map<String, List<CamposCatalogo>> map = new HashMap<String, List<CamposCatalogo>>();
          CatalogoService catalgoService = new CatalogoService();
          List<AtributoCatalogo> lstAtributosCatalogos = null;
          List<ValorCatalogo> lstValoresCatalogo = null;
          try {
              lstAtributosCatalogos = catalgoService.getAtributosCatalogo(idCat);
              lstValoresCatalogo = catalgoService.getValorCatalogo(idCat);
              if (lstAtributosCatalogos != null) {
                  for (int i = 0; i < lstAtributosCatalogos.size(); i++) {
                      List<CamposCatalogo> listaCampos=new ArrayList<CamposCatalogo>();
                      int idLlave = lstAtributosCatalogos.get(i).getId();

                      for (int j = 0; j < lstValoresCatalogo.size(); j++) {
                          if (idLlave == lstValoresCatalogo.get(j).getAtributosCatalogo().getId()) {
                              CamposCatalogo camp = new CamposCatalogo();
                              camp.setId(lstValoresCatalogo.get(j).getId());
                              camp.setValor(lstValoresCatalogo.get(j).getValor());
                              listaCampos.add(camp);
                          }
                      }

                      String atributo=lstAtributosCatalogos.get(i).getAtributo();
                      map.put(atributo, listaCampos);
                  }
              }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
          return map;
    }
   
}
